package com.meihua.shellapp.adapter.personalcenter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.TextView;

import com.aspsine.irecyclerview.IViewHolder;
import com.meihua.shellapp.R;
import com.meihua.shellapp.adapter.OnItemClickListener;
import com.meihua.shellapp.bean.MessageListBean;
import com.meihua.shellapp.utils.DateUtils;
import com.meihua.shellapp.view.ExpandableTextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by ${zhangyuanchao} on 2017/9/28.
 */

public class MessageLVAdapter extends RecyclerView.Adapter<MessageLVAdapter.ViewHolder> {
    private List<MessageListBean.DataBean> mData;

    public MessageLVAdapter(List<MessageListBean.DataBean> mData) {
        this.mData = mData;
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    private OnItemClickListener mOnItemClickListener;

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message_lv, parent, false));
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.tv_name.setText(mData.get(position).getText_title());
        holder.tv_time.setText(DateUtils.getInstance().getTime(mData.get(position).getSend_time()));
        holder.tv_con.setText(mData.get(position).getText_content());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final int position = holder.getIAdapterPosition();
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.onItemClick(position, v);
                }
            }
        });
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    class ViewHolder extends IViewHolder {
        @Bind(R.id.tv_name)
        TextView tv_name;
        @Bind(R.id.tv_con)
        ExpandableTextView tv_con;
        @Bind(R.id.tv_time)
        TextView tv_time;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
